﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>修改密码</title>
    <style>

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            background: #f5f5f5;
        }

        .main-layout {
            display: flex;
            max-width: 1000px;
            margin: 30px auto 0 auto;
            min-height: 600px;
        }

        .sidebar {
            width: 220px;
            background: white;
            border-radius: 8px;
            padding: 15px 0;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            margin-right: 24px;
            flex-shrink: 0;
        }

        .menu-item {
            padding: 12px 20px;
            cursor: pointer;
            transition: all 0.3s;
            color: #666;
        }

            .menu-item:hover {
                background: #f5f5f5;
                color: #333;
            }

            .menu-item.active {
                color: #1890ff;
                background: #e6f7ff;
                border-right: 3px solid #1890ff;
            }

            .menu-item a {
                text-decoration: none;
            }

        .content {
            flex: 1;
            background: white;
            padding: 25px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            min-width: 0;
        }

        .form-group {
            margin-bottom: 20px;
        }

        label {
            display: block;
            margin-bottom: 8px;
            color: #666;
            font-weight: bold;
        }

        input[type="password"] {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 16px;
        }

        button {
            background: #3498db;
            color: white;
            padding: 12px 24px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            transition: background 0.3s;
        }

            button:hover {
                background: #2980b9;
            }

        .password-form {
            max-width: 500px;
            margin-top: 30px;
        }

        h1 {
            margin-bottom: 30px;
            color: #333;
        }
    </style>
</head>
<body>
    <div class="top-bar">
        <div class="user-info">
            <span class="username">@ViewBag.UserName</span>
        </div>
    </div>
    <div class="main-layout">
        <div class="sidebar">
            <div class="menu-item @(ViewBag.ActiveMenu == "Person" ? "active" : "")" onclick="location.href='@Url.Action("Person", "Home")'">基本信息</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "Uploadface" ? "active" : "")" onclick="location.href='@Url.Action("Uploadface", "Home")'">上传头像</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "Blog" ? "active" : "")" onclick="location.href='@Url.Action("Blog", "Home")'">我的博客</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "ModifyData" ? "active" : "")" onclick="location.href='@Url.Action("ModifyData", "Home")'">修改资料</div>
            <div class="menu-item @(ViewBag.ActiveMenu == "ChangePassword" ? "active" : "")" onclick="location.href='@Url.Action("ChangePassword", "Home")'">修改密码</div>
            <div class="menu-item" onclick="location.href='@Url.Action("index", "Default")'">返回</div>
        </div>
        <div class="content">
            <h1>修改密码</h1>
            @using (Html.BeginForm("ChangePassword","Home", FormMethod.Post, new { id = "passwordForm", @class = "password-form" })) {
                @Html.AntiForgeryToken()
                <div class="form-group">
                    <label>原密码</label>
                    <input type="password" id="oldPassword" name="oldPassword" required>
                </div>
                <div class="form-group">
                    <label>新密码</label>
                    <input type="password" id="newPassword" name="newPassword" required>
                </div>
                <div class="form-group">
                    <label>确认新密码</label>
                    <input type="password" id="confirmPassword" name="confirmPassword" required>
                </div>
                <button type="submit">提交</button>
            }
        </div>
    </div>
    <script>
        //基本信息跳转
        function Person() {
            window.location.href = 'Person';
        }
        //上传头像跳转
        function Uploadface() {
            window.location.href = 'Uploadface';
        }
        //我的博客跳转
        function Blog() {
            window.location.href = 'Blog';
        }
        //修改资料跳转
        function ModifyData() {
            window.location.href = 'ModifyData';
        }

        // 侧边栏菜单切换
        document.querySelectorAll('.menu-item').forEach(item => {
            item.addEventListener('click', function () {
                document.querySelectorAll('.menu-item').forEach(i => i.classList.remove('active'));
                this.classList.add('active');
            });
        });
        // 客户端基础校验：保持表单原生提交，由后端处理
        document.getElementById('passwordForm').addEventListener('submit', function (e) {
            const newPassword = document.getElementById('newPassword').value;
            const confirmPassword = document.getElementById('confirmPassword').value;
            if (newPassword !== confirmPassword) {
                e.preventDefault();
                alert('新密码和确认密码不一致！');
            }
        });
    </script>
    @if (TempData["ErrorMessage"] != null)
    {
        <script>
            alert('@TempData["ErrorMessage"]');
        </script>
    }
    @if (TempData["SuccessMessage"] != null)
    {
        <script>
            alert('@TempData["SuccessMessage"]');
        </script>
    }
</body>
</html>
